<#assign module="marketing"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/gird.css">
</@override>
<@override name="body">
<div class="row">
 	<div class="col-xs-12">
 		<button class="pull-right button button-rounded button-flat-blue" onclick="window.location='${ctx}/couponrule/add';"><i class="icon-plus"></i>&nbsp;添加优惠劵规则</button>
	</div>
</div>
<div class="row margin-top">
	<div class="col-xs-12">
	<div class="panel panel-primary">
	<div class="table-responsive">
		<table class="table table-hover table-striped">
			<thead>
			<tr style="font-size:14px;">
				<th>状态</th>
				<th>编码</th>
				<th>名称</th>
				<th>金额</th>
				<@shiro.isMainCompany>
				<th>所属公司</th>
				</@shiro.isMainCompany>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
				<#if (page.content)?? >
			  	<#list page.content as data>
					<tr>
						<td class="status-td">
							<#if data.lapsed>
								已失效
							<#else>
								<#if data.timeStatus==0>
									未开始
								<#elseif data.timeStatus==1>
									使用中
								<#elseif data.timeStatus==2>
									已过期
								</#if>
							</#if>
						</td>
						<td>${data.code?if_exists}</td>
						<td>${data.title?if_exists}</td>
						<td>${data.money?if_exists}</td>
						<@shiro.isMainCompany>
							<td><#--${data.company.abbreviation?if_exists}--></td>
						</@shiro.isMainCompany>
						<td>${data.start?string('yyyy/MM/dd HH:mm')}</td>
						<td>${data.end?string('yyyy/MM/dd HH:mm')}</td>
						<td>
							<a href="javascript:;" data-value="${data.id}" class="btn-link deletethis">删除</a>
							<#if !data.lapsed>
								<a href="javascript:;" data-value="${data.id}" class="btn-link lapsedthis">失效</a>
							</#if>
							<a href="${ctx}/couponrule/coupon/${data.id}" class="btn-link">查看已生成优惠劵</a>
							<a href="${ctx}/couponrule/mass/${data.id}" class="btn-link">生成优惠劵</a>
						</td>
						
					</tr>
				</#list>
				</#if>
			</tbody>
		</table>
		<#if page.totalElements??>
		<ul class="pagination pull-right pagination-sm">
			<li><a>共 ${page.totalElements} 条数据</a></li>
			<@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/couponrule/list">
				<@pg.index>
					<@pg.first>
						<li><a href="${pageUrl}">&laquo;</a></li>
					</@pg.first>
					<@pg.prev>
						<li><a href="${pageUrl}">&lsaquo;</a></li>
					</@pg.prev>
					<@pg.pages>
						<#if  currentPageNumber == pageNumber >
							<li class="active"><a href="#">${pageNumber}</a></li>
						<#else>
							<li><a href="${pageUrl}">${pageNumber}</a></li>
						</#if>
					</@pg.pages>
					<@pg.next>
						<li><a href="${pageUrl}">&rsaquo;</a></li>
					</@pg.next>
					<@pg.last>
						<li><a href="${pageUrl}">&raquo;</a></li>
					</@pg.last>
				</@pg.index>
			</@pg.pager>
		</ul>
		</#if>
	</div>
	</div>
	</div>
</div>
</@override>
<@override name="footer">
<script type="text/javascript">
	var thisButton;
	function deleteCouponRule() {
	    $.post('${ctx}/couponrule/delete',{'id':thisButton.attr("data-value")},function(data){
	            if(data.success){
	                $.scojs_message('优惠劵删除成功', $.scojs_message.TYPE_OK);
	                window.location.reload(true);//强制刷新
	            } else {
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
	    },'json');
	}
	function lapsedCouponRule() {
	    $.post('${ctx}/couponrule/lapsed',{'id':thisButton.attr("data-value")},function(data){
	            if(data.success){
	                $.scojs_message('操作成功', $.scojs_message.TYPE_OK);
	                window.location.reload(true);//强制刷新
	            } else {
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
	    },'json');
	}
	$(document).ready(function(){
	    $(".deletethis").click(function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "删除该优惠劵也会使其所对应的活动失效并且会删除用户所持优惠劵等数据。<br/>你真的要删除该优惠劵吗？",
	            action:deleteCouponRule
	          });
	          confirm.show();
	    });
	    
	    $(".lapsedthis").click(function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "该优惠劵失效也会使其所对应的活动失效。<br/>确认要继续执行吗？（失效后不可逆转）",
	            action:lapsedCouponRule
	          });
	          confirm.show();
	    });
	    
	});
</script>
</@override>
<@extends name="../layout.ftl"/>